/*
 * Copyright 2009-2011 Prime Technology.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.webermagem.model;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

public class UsuarioDataModel extends ListDataModel<Usuario> implements SelectableDataModel<Usuario>, Serializable {  

	private static final long serialVersionUID = 6037120041415075664L;

	public UsuarioDataModel() {}

    public UsuarioDataModel(List<Usuario> data) {
        super(data);
    }
    
	@SuppressWarnings("unchecked")
	public Usuario getRowData(String rowKey) {
        
    	long key = Long.parseLong(rowKey) ;
    			
        List<Usuario> list = (List<Usuario>) getWrappedData();
        
        for(Usuario usr : list) {
            if(usr.getId() == key)
                return usr;
        }
        
        return null;
    }

    public Object getRowKey(Usuario p) {
        return p.getId();
    }
}
